<template>
  <el-container id="home-container">
    <!-- 侧边栏 -->
    <el-aside width="auto">
      <menu-aside></menu-aside>
    </el-aside>

    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <div>
          <el-button
            type="primary"
            @click="handleMenu"
            icon="el-icon-menu"
            size="mini"
            plain
            style="border:none;margin-left:10px;border-color:#8c939d"
          ></el-button>
        </div>
        <div style="position:absolute;width:500px;margin-left:80px;">
          <el-image
            class="wow slideInLeft"
            :src="require('../assets/css/images/bulletin.svg')"
            style="width:25px;height:25px;margin-left:100px;position:absolute;"
          ></el-image>
          <marquee
            behavior="scroll"
            scrolldelay="1"
            style="width:200px;margin-left:120px;font-size:14px"
            >你好{{ username }} <span v-html="`${message}`"></span
          ></marquee>
        </div>

        <div class="wow slideInLeft">
          <el-input
            placeholder="搜索文件"
            class="searchClass"
            @click.native="list"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              class="searchButton"
            ></el-button>
          </el-input>
        </div>
        <div style="position:absolute;width:100px;margin-left:70%;">
          <el-image
            class="wow slideInLeft"
            :src="require('../assets/css/images/connectAdmin.svg')"
            @click="searchDialog = true"
            style="width:25px;height:25px;margin-left:100px;position:absolute;cursor:pointer"
          ></el-image>
        </div>
        <el-badge
          :value="messageNum"
          class="item"
          is-dot
          style="margin-right:25%;cursor:pointer"
          @click.native="messageDrawer = true"
        >
          <img
            src="../assets/css/images/message.svg"
            style="width:28px;height:28px"
          />
        </el-badge>
        <el-dropdown>
          <!-- <b style="color:white">admin</b> -->
          <!-- 头像 -->
          <el-avatar
            :src="require('../assets/css/images/panda.jpg')"
            style="margin-right: 20px"
            :fit="fill"
          ></el-avatar>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logout()"
              >退出登录</el-dropdown-item
            >
            <el-dropdown-item @click.native="dialog = true"
              >个人信息</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <!-- 主体 -->
      <el-main>
        <!-- 渐变效果 -->
        <transition name="fade" mode="out-in">
          <router-view></router-view>
        </transition>
        <!-- 个人信息 -->
        <el-drawer
          title="个人信息"
          :before-close="handleClose"
          :visible.sync="dialog"
          direction="rtl"
          custom-class="drawer"
          ref="drawer"
          style="text-align:center"
        >
          <div class="ddrawer_content">
            <!-- TODO头像接口 -->
            <!-- <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
            > -->
            <!-- <i class="el-icon-plus avatar-uploader-icon"  @click="selectFile"></i> -->
            <!-- TODO图片路径 -->
            <img
              :src="require('../assets/css/images/panda.jpg')"
              v-show="img"
              class="avatar"
              @click="selectFile"
            />
            <input
              type="file"
              ref="file"
              style="display:none;"
              @change="fileChange"
            />
            <!-- </el-upload> -->
            <br />
            <el-form :model="form">
              <el-form-item label="用户名" :label-width="formLabelWidth">
                <el-input
                  v-model="this.username"
                  autocomplete="off"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="手机号码" :label-width="formLabelWidth">
                <el-input
                  v-model="form.mobile"
                  autocomplete="off"
                  disabled
                ></el-input>
              </el-form-item>
              <el-form-item label="密码" :label-width="formLabelWidth">
                <el-input
                  v-model="form.password"
                  autocomplete="off"
                  show-password
                ></el-input>
              </el-form-item>
              <el-form-item label="邮箱" :label-width="formLabelWidth">
                <el-input
                  v-model="form.email"
                  autocomplete="off"
                  disabled
                ></el-input>
              </el-form-item>
              <!-- <el-form-item label="组群" :label-width="formLabelWidth">
                <el-input v-model="form.group" autocomplete="off"></el-input>
              </el-form-item> -->
            </el-form>
            <div class="drawer_footer">
              <el-button @click="cancelForm">返 回</el-button>
              <el-button
                type="primary"
                @click="$refs.drawer.closeDrawer()"
                :loading="loading"
                >{{ loading ? "提交中 ..." : "确 定" }}</el-button
              >
            </div>
          </div>
        </el-drawer>
        <!-- 消息 -->
        <el-drawer
          title="站内信息"
          :visible.sync="messageDrawer"
          :with-header="false"
        >
          <message-content></message-content>
        </el-drawer>
        <!-- 反馈对话框 -->
        <el-dialog
          title="联系管理员"
          :visible.sync="searchDialog"
          center
          class="searchDialog"
        >
          <p>反馈内容：</p>
          <el-input
            placeholder="请输入内容"
            type="textarea"
            v-model="suggestForm.suggest"
          ></el-input>
          <p>问题严重程度：</p>
          <el-rate v-model="suggestForm.suggestLevel" :colors="colors">
          </el-rate>
          <span slot="footer" class="dialog-footer">
            <el-button @click="searchDialog = false">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
          </span>
        </el-dialog>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import menuAside from "../components/management/menuAside.vue";
import { component as VueContextMenu } from "@xunlei/vue-context-menu";
import message from "../components/system/message.vue";
import messageContent from "../components/system/messageContent.vue";
import { mapState } from "vuex";
// import searchPage from "./system/searchPage.vue";
import commonHead from "./commonHead.vue";
export default {
  name: "system",
  components: {
    VueContextMenu,
    menuAside,
    message,
    messageContent,
    // searchPage,
    commonHead,
  },
  data() {
    return {
      file: [],
      state: "",
      timeout: null,
      dialog: false,
      img: "../assets/css/images/panda.jpg",
      loading: false,
      username: "",
      form: {
        name: "admin",
        mobile: "19939707043",
        password: "123456",
        email: "1252536388@qq.com",
        group: "计科181",
      },
      formLabelWidth: "80px",
      timer: null,
      contextMenuTarget: null,
      contextMenuVisible: false,
      messageDrawer: false,
      searchDialog: false,
      //消息数
      messageNum: "1",
      tags: "",

      suggestForm: {
        // 反馈内容
        suggest: "",
        // 反馈程度
        suggestLevel: "",
      },
      colors: ["#09cc6e", "#F7BA2A", "#ef4a4a"],
      rid: 0,
      message:
        "，欢迎来到教学资源管理平台，目前系统尚未完善，正在全力开发。。。",
    };
  },
  computed: {
    ...mapState({
      tag: (state) => state.tab.tabsList,
    }),
  },
  created() {
    // this.getChartList()
  },
  mounted() {
    new this.$wow.WOW().init();
    // var username = this.$route.query.key;
    var username = localStorage.getItem("key");
    this.username = username;
  },
  methods: {
    // XSS() {
    //   const xss = require("xss");
    //   const ret = xss(html, {
    //     whiteList: {
    //       img: ["src"],
    //       a: ["href"],
    //       font: ["color", "size"],
    //       // 过滤掉类似script,noscript标签
    //       stripIgnoreTagBody: ["script", "noscript"],
    //     },
    //     onIgnoreTag() {
    //       return "";
    //     },
    //   });
    //   return ret;
    // },
    list() {
      this.$router.push("/system/searchPage");
    },
    selectFile() {
      this.$refs.file.click();
    },
    // 文件选择后触发
    fileChange(e) {
      // 通过DOM取文件数据
      const file = this.$refs.file.files[0];
      // 计算文件大小 KB
      const size = Math.floor(file.size / 1024);
      // 显示本地图片
      this.img = window.URL.createObjectURL(file);

      // 使用 FormData 构建表单数据
      const formData = new FormData();
      formData.append("file", file);
      // 这里使用 axios 上传文件
      this.$axios
        .post("common/upload", formData, {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        })
        .then((res) => {
          // ...
        });
    },
    handleMenu() {
      this.$store.commit("collapesMenus");
    },
    click() {
      console.log(this.$route.path);
    },
    messagePush(content) {
      this.$message(content);
    },
    logout() {
      //清空token
      window.sessionStorage.clear();
      this.$router.push("/home");
      window.localStorage.clear();
    },
    //获取图表数据
    async getChartList() {
      const { data: res } = await this.$http.get("charts");
      if (res.data.status !== 200) return this.$message.error(res.meta.msg);
      this.chartList = res.data;
    },
    createStateFilter(queryString) {
      return (state) => {
        return (
          state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    handleClose(done) {
      if (this.loading) {
        return;
      }
      this.$confirm("确定修改个人信息吗？")
        .then((_) => {
          this.loading = true;
          this.timer = setTimeout(() => {
            done();
            this.$message({
              type: "success",
              message: "修改成功",
            });
            // 动画关闭需要一定的时间
            setTimeout(() => {
              this.loading = false;
            }, 400);
          }, 1000);
        })
        .catch((_) => {});
    },
    cancelForm() {
      this.loading = false;
      this.dialog = false;
      clearTimeout(this.timer);
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    // 提交反馈信息
    submit() {
      // TODO
      this.$http.post(`${this.systemURL}/advice/add`, this.suggestForm).then((res) => {
        if (res.status == 200) {
          this.$message.success("反馈成功！");
          this.searchDialog = false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
#home-container {
  height: 100%;
  overflow-x: hidden !important;
}
.el-header {
  display: flex;
  width: auto;
  justify-content: space-between;
  padding-left: 0;
  height: 50px !important;
  border-bottom: 2px solid #dfe2e4;
  background-color: white;
  align-items: center;
  color: rgb(7, 7, 7);
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
    }
    span {
      margin-left: 15px;
    }
  }
}
/deep/.el-dialog {
  // height: 80%;
  border-radius: 10px !important;
  opacity: 0.9;
}
.el-aside {
  background-color: #3a3d41;
  border-right: 3px solid #393d3f !important;
  box-shadow: #898d8f;
  overflow: hidden;
}
/deep/.searchClass {
  right: 10%;
  width: 200px;
  height: 35px !important;
  background-color: #f3f3f3;
  border-radius: 20px;
}
/deep/.searchClass:hover {
  width: 450px;
  transition: all 0.5s;
  background-color: #ffffff;
  border: 1.7px solid #00bfff;
}
/deep/.searchClass .el-input-group__prepend {
  border: none;
  background-color: transparent;
  padding: 0 10px 0 30px;
}
/deep/.searchClass .el-input-group__append {
  border: none;
  border-color: #545c64;
  background-color: transparent;
}
/deep/.searchClass .el-input__inner {
  height: 36px;
  line-height: 36px;
  border-radius: 20px;
  border: none;
  background-color: transparent;
}
/deep/.searchClass .el-icon-search {
  font-size: 16px;
}
/deep/.searchClass .centerClass {
  height: 100%;
  line-height: 100%;
  display: inline-block;
  vertical-align: middle;
  text-align: right;
}
/deep/.searchClass .line {
  width: 1px;
  height: 26px;
  background-color: #0f7af5;
  margin-left: 14px;
}
/deep/.searchClass:hover .line {
  background-color: #07b2f0;
  border: none;
}
/deep/.searchClass:hover .el-icon-search {
  color: #409eff;
  border: none;
  font-size: 16px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.item {
  position: absolute !important;
  right: -15%;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
  margin-left: 30%;
  cursor: pointer;
}
.el-main {
  background-color: #eef2f3;
  // background: url("../assets/css/images/blurpage.png");
  // background-attachment: fixed;
  // background-position: center;
  // background-repeat: no-repeat;
  // background-size: 120% 120%;
  // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
}
.iconfont {
  padding-right: 10px;
}
.fade-enter-active,
.fade-leave-active {
  transition: all 0.2s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
</style>
